package com.snuproject.lgt.activity;

import com.snuproject.lgt.R;
import com.snuproject.lgt.imgtrans.CameraPreview;

import android.app.Activity;
import android.content.Intent;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;

public class ActivityPhoto extends Activity {
	
	private CameraPreview mPreview;
	private Activity mActivity;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_photo);
        
        mActivity = this;
        
        // Hide the window title.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        // Create our Preview view and set it as the content of our activity.
        mPreview = new CameraPreview(this);
        LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
        mPreview.setLayoutParams(lp);
        setContentView(mPreview);
        
        Button btCheese = new Button(this);
        btCheese.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        btCheese.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onClickCheese(v);
			}
		});
        btCheese.setText("cheese");
        addContentView(btCheese, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        
        /*
        android:id="@+id/photo_bt_cheese"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="87dp"
        android:onClick="onClickCheese"
        android:text="cheese" />
         */
    }
    
    public void onClickCheese(View view) {
    	
    	ShutterCallback shutter = new ShutterCallback() {
			
			public void onShutter() {
				// TODO Auto-generated method stub
			}
		};
		
		PictureCallback raw = new PictureCallback() {
			
			public void onPictureTaken(byte[] data, Camera camera) {
				// TODO Auto-generated method stub
			}
		};

		PictureCallback jpeg = new PictureCallback() {
			
			public void onPictureTaken(byte[] data, Camera camera) {
				// TODO Auto-generated method stub

		    	Intent intent = new Intent(mActivity, ActivityResult.class);
		    	
		    	Bundle bundle = new Bundle();
		    	bundle.putByteArray("img_data", data);
		    	intent.putExtras(bundle);
		    	startActivity(intent);
			}
		};
		
		mPreview.takePicture(shutter, raw, jpeg);
    	
    }
}
